package main.java.chessfootball.rules.checker;

import main.java.chessfootball.model.regulation.Mode;

/**
 * User: Igor
 * Date: 28.07.2011
 * Time: 6:53:33
 */
public class PutLimitChecker extends AbstractPutChecker
{
	@Override
	public boolean valid()
	{
		if (put.getPlayer() > game.getRule().getMatch().getPlayersCount())
		{
			return false;
		}
		if ((game.getMatch().getMode().equals(Mode.OUT_GAME)) && (game.getRule().getMatch()
				.getTimeRule(game.getMatch().getTime().getPeriod()).isIterationOutGame()))
		{
			int startPlayer = game.getMatch().getTime().getStartSide().equals(put.getSide()) ? 1 : 0;
			if (put.getPlayer() > game.getField().getTeam(put.getSide().getInvert())
					.getPlayersCount() + startPlayer)
			{
				return false;
			}
		}
		return true;
	}
}
